package com.tony.study.designMode.DM4_原型模式.DM4;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

/**
 * Created with IntelliJ IDEA.
 *
 * @Title: SexEnum
 * @Auther: 皮蛋布丁
 * @Date: 2021/11/01/17:36
 * @Description: 性别枚举类
 */
public enum SexEnum {
    /**
     * 枚举对象
     */
    MALE("男",0),
    FEMALE("女",1);

    private final String name;
    private final Integer value;

    /**
    * @Description: SexEnum 枚举构造器
    * @Param: [name 性别名称, value 性别值]
    * @return:
    * @Author: 皮蛋布丁
    * @Date: 2021/11/1 17:37
    */
    SexEnum(String name, Integer value) {
        this.name = name;
        this.value = value;
    }

    public String getName() {
        return name;
    }
    
    @JsonValue
    public Integer getValue() {
        return value;
    }
    /**
    * @Description: getEnum 通过name获取对应的枚举对象
    * @Param: [name 类型名称]
    * @return: com.tony.study.designMode.MD4_原型模式.MD4.SexEnum
    * @Author: 皮蛋布丁
    * @Date: 2021/11/1 17:39
    */
    public static SexEnum getEnum(String name){
        for(SexEnum sexEnum : SexEnum.values()){
            if(name.equals(sexEnum.getName())){
                return  sexEnum;
            }
        }
        return  null;
    }

    /**
    * @Description: getEnum 通过value获取对应的枚举对象
    * @Param: [value 类型值]
    * @return: com.tony.study.designMode.MD4_原型模式.MD4.SexEnum
    * @Author: 皮蛋布丁
    * @Date: 2021/11/1 17:40
    */
    @JsonCreator
    public static SexEnum getEnum(Integer value){
        for(SexEnum sexEnum : SexEnum.values()){
            if(value.equals(sexEnum.getValue())){
                return  sexEnum;
            }
        }
        return  null;
    }
}
